package event

import (
	"encoding/json"
	"fmt"
	"time"

	"gorm.io/gorm"
)

type DomainEventStore struct {
	gorm.Model
	EventID    string    `gorm:"comment:事件ID"`
	EntityID   string    `gorm:"comment:实体ID"`
	EventTime  time.Time `gorm:"comment:事件时间"`
	EventBody  string    `gorm:"comment:事件体"`
	EventType  string    `gorm:"comment:事件类型"`
	EventState int       `gorm:"comment:事件状态"`
}

func (d DomainEventStore) TableName() string {
	return "domain_event_store"
}

func (d DomainEventStore) String() string {
	marshal, _ := json.Marshal(d)
	return string(marshal)
}

type DomainEvent interface {
	fmt.Stringer
	ID() string
	OccurredOn() time.Time
	GetEventName() string
	GetEntityID() string
}
